{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据文件的读取详解\n",
    "\n",
    "* read_csv的常用参数\n",
    "* names,sep,dtype,header,parse_dates,encoding"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#help(pd.read_csv)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* sep 用来定义分隔符\n",
    "\n",
    "* names用来自定义列表\n",
    "\n",
    "* dtype来定义列的类型，特别是想改变默认类型的时候"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user</th>\n",
       "      <th>brand</th>\n",
       "      <th>behavr</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>0</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>2</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>2</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>0</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>0</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       user  brand  behavr   date\n",
       "0  10944750  13451       0  06/04\n",
       "1  10944750  13451       2  06/04\n",
       "2  10944750  13451       2  06/04\n",
       "3  10944750  13451       0  06/04\n",
       "4  10944750  13451       0  06/04"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1=pd.read_csv(r\"D:\\t_alibaba_data3.txt\",names=[\"user\",\"brand\",\"behavr\",\"date\"],sep=\"\\t\",dtype={\"behavr\":int})\n",
    "r1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#r1.behavr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user</th>\n",
       "      <th>brand</th>\n",
       "      <th>behavr</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>0</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>2</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>2</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>0</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>0</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       user  brand  behavr   date\n",
       "0  10944750  13451       0  06/04\n",
       "1  10944750  13451       2  06/04\n",
       "2  10944750  13451       2  06/04\n",
       "3  10944750  13451       0  06/04\n",
       "4  10944750  13451       0  06/04"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1=pd.read_csv(r\"D:\\try\\t_alibaba_data31.txt\",sep=\"\\t\")\n",
    "r1.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* header用来设置使用数据第几行作为列标，和names联合使用可以替代数据列标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "      <th>d</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>0</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>2</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>2</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>0</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>0</td>\n",
       "      <td>06/04</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          a      b  c      d\n",
       "0  10944750  13451  0  06/04\n",
       "1  10944750  13451  2  06/04\n",
       "2  10944750  13451  2  06/04\n",
       "3  10944750  13451  0  06/04\n",
       "4  10944750  13451  0  06/04"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1=pd.read_csv(r\"D:\\try\\t_alibaba_data31.txt\",names=[\"a\",\"b\",\"c\",\"d\"],header=0,sep=\"\\t\")\n",
    "r1.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* parse_dates用来自动解析时间数据，注意前提是格式要符合要求"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "      <th>d</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>0</td>\n",
       "      <td>2011-06-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>2</td>\n",
       "      <td>2011-06-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>2</td>\n",
       "      <td>2011-06-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10944750</td>\n",
       "      <td>13451</td>\n",
       "      <td>0</td>\n",
       "      <td>2011-06-04</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          a      b  c          d\n",
       "0  10944750  13451  0 2011-06-04\n",
       "1  10944750  13451  2 2011-06-04\n",
       "2  10944750  13451  2 2011-06-04\n",
       "3  10944750  13451  0 2011-06-04"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1=pd.read_csv(r\"D:\\try\\t_alibaba_data311.txt\",names=[\"a\",\"b\",\"c\",\"d\"], header=0, sep=\"\\t\",parse_dates=[3])\n",
    "r1.head()\n",
    "#通过parse_dates自动解析时间数据，[3]代表解析3号位也就是第四列数据cv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   2011-06-04\n",
       "1   2011-06-04\n",
       "2   2011-06-04\n",
       "3   2011-06-04\n",
       "Name: d, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1.d"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* xls数据用read_xls，xls转化csv\n",
    "* encoding用来定义解析数据使用的编码格式，默认使用utf-8来进行解析，当你发现数据无法解析的时候可以尝试更换编码格式，再读取带中文的数据，特别是xls转成的csv数据时很常用\n",
    "\n",
    "除utf-8外的主要中文编码：gb2312 gbk gb18030"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>企业</th>\n",
       "      <th>部门</th>\n",
       "      <th>职位</th>\n",
       "      <th>工号</th>\n",
       "      <th>响应状态</th>\n",
       "      <th>签到时间</th>\n",
       "      <th>是否迟到</th>\n",
       "      <th>非受邀</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>项欣瑶</td>\n",
       "      <td>杭州师范大学阿里巴巴商学院</td>\n",
       "      <td>杭州师范大学阿里巴巴商学院-在校学生-在校本科生-电子商务-19级-电商191</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>未响应</td>\n",
       "      <td>2019-10-15 11:59:52</td>\n",
       "      <td>迟到</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>斯煜佳</td>\n",
       "      <td>杭州师范大学阿里巴巴商学院</td>\n",
       "      <td>杭州师范大学阿里巴巴商学院-在校学生-在校本科生-国际商务-19级-国商191</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>未响应</td>\n",
       "      <td>2019-10-15 11:59:52</td>\n",
       "      <td>迟到</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>王佳旋</td>\n",
       "      <td>杭州师范大学阿里巴巴商学院</td>\n",
       "      <td>杭州师范大学阿里巴巴商学院-在校学生-在校本科生-电子商务-19级-电商191</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>未响应</td>\n",
       "      <td>2019-10-15 11:59:54</td>\n",
       "      <td>迟到</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>罗佳怡</td>\n",
       "      <td>杭州师范大学阿里巴巴商学院</td>\n",
       "      <td>杭州师范大学阿里巴巴商学院-在校学生</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>未响应</td>\n",
       "      <td>2019-10-15 11:59:54</td>\n",
       "      <td>迟到</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>张滨滨</td>\n",
       "      <td>杭州师范大学阿里巴巴商学院</td>\n",
       "      <td>杭州师范大学阿里巴巴商学院-在校学生</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>未响应</td>\n",
       "      <td>2019-10-15 11:59:54</td>\n",
       "      <td>迟到</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名             企业                                       部门  职位  工号 响应状态  \\\n",
       "0  项欣瑶  杭州师范大学阿里巴巴商学院  杭州师范大学阿里巴巴商学院-在校学生-在校本科生-电子商务-19级-电商191 NaN NaN  未响应   \n",
       "1  斯煜佳  杭州师范大学阿里巴巴商学院  杭州师范大学阿里巴巴商学院-在校学生-在校本科生-国际商务-19级-国商191 NaN NaN  未响应   \n",
       "2  王佳旋  杭州师范大学阿里巴巴商学院  杭州师范大学阿里巴巴商学院-在校学生-在校本科生-电子商务-19级-电商191 NaN NaN  未响应   \n",
       "3  罗佳怡  杭州师范大学阿里巴巴商学院                       杭州师范大学阿里巴巴商学院-在校学生 NaN NaN  未响应   \n",
       "4  张滨滨  杭州师范大学阿里巴巴商学院                       杭州师范大学阿里巴巴商学院-在校学生 NaN NaN  未响应   \n",
       "\n",
       "                  签到时间 是否迟到  非受邀  \n",
       "0  2019-10-15 11:59:52   迟到  NaN  \n",
       "1  2019-10-15 11:59:52   迟到  NaN  \n",
       "2  2019-10-15 11:59:54   迟到  NaN  \n",
       "3  2019-10-15 11:59:54   迟到  NaN  \n",
       "4  2019-10-15 11:59:54   迟到  NaN  "
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1=pd.read_csv(r\"D:\\try\\xxx.csv\",encoding=\"gb18030\")\n",
    "r1.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* chunksize 当数据超出内存总量时通过设置chunksize来分段读取其中部分，chunksize用来定义一次读取的行数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pandas.io.parsers.TextFileReader at 0x2573fba4278>"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv(r\"D:\\t_alibaba_data3.txt\",names=[\"user\",\"brand\",\"behavr\",\"date\"],sep=\"\\t\",chunksize=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       user  brand  behavr   date\n",
      "0  10944750  13451       0  06/04\n",
      "1  10944750  13451       2  06/04\n",
      "2  10944750  13451       2  06/04\n",
      "3  10944750  13451       0  06/04\n",
      "4  10944750  13451       0  06/04\n",
      "5  10944750  13451       0  06/04\n",
      "6  10944750  13451       0  06/04\n",
      "7  10944750  13451       0  06/04\n",
      "8  10944750  21110       0  06/07\n",
      "9  10944750   8689       0  05/02\n",
      "        user  brand  behavr   date\n",
      "10  10944750   8689       2  05/02\n",
      "11  10944750   8689       2  05/02\n",
      "12  10944750   8689       0  05/02\n",
      "13  10944750   8689       0  05/02\n",
      "14  10944750  26619       0  06/28\n",
      "15  10944750   5185       0  07/10\n",
      "16  10944750  18575       0  05/02\n",
      "17  10944750  23662       0  06/19\n",
      "18  10944750  23662       0  06/19\n",
      "19  10944750  15761       0  04/24\n",
      "        user  brand  behavr   date\n",
      "20  10944750  15761       0  04/24\n",
      "21  10944750  15761       0  04/24\n",
      "22  10944750  15761       0  04/24\n",
      "23  10944750  19673       0  07/05\n",
      "24  10944750  19673       0  07/05\n",
      "25  10944750  19673       0  07/05\n",
      "26  10944750  19673       0  07/05\n",
      "27  10944750  19673       0  07/04\n",
      "28  10944750  19673       0  07/04\n",
      "29  10944750  19673       1  07/05\n"
     ]
    }
   ],
   "source": [
    "k=0\n",
    "for i in pd.read_csv(r\"D:\\t_alibaba_data3.txt\",names=[\"user\",\"brand\",\"behavr\",\"date\"],sep=\"\\t\",chunksize=10):\n",
    "    print(i)\n",
    "    k=k+1\n",
    "    if k==3:break\n",
    "#加了chunksize的read_csv变成了一个迭代子,每次读入十行数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "brand\n",
      "1996      4.0\n",
      "4078      1.0\n",
      "5185      1.0\n",
      "6290      3.0\n",
      "7373      4.0\n",
      "8628      5.0\n",
      "8689      5.0\n",
      "9817      1.0\n",
      "11465     1.0\n",
      "13451     8.0\n",
      "13779     1.0\n",
      "14580     1.0\n",
      "15315     2.0\n",
      "15761     4.0\n",
      "15980     1.0\n",
      "18575     1.0\n",
      "19673     7.0\n",
      "21110     1.0\n",
      "21501     4.0\n",
      "23251     3.0\n",
      "23662     2.0\n",
      "25687    29.0\n",
      "26619     1.0\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "k=0\n",
    "for i in pd.read_csv(r\"D:\\t_alibaba_data3.txt\",names=[\"user\",\"brand\",\"behavr\",\"date\"],sep=\"\\t\",chunksize=30):\n",
    "    z=i.groupby(\"brand\").size()\n",
    "    #print(z)\n",
    "    if k==0:\n",
    "        s=z\n",
    "    else:\n",
    "        s=s.add(z,fill_value=0)\n",
    "    k=k+1\n",
    "    if k==3:break\n",
    "print(s)\n",
    "\n",
    "#统计后的结果往往比原始记录小\n",
    "#结果合并的方法根据统计结果而定，如果结果是数据框，则可能需要concat"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 课间题\n",
    "\n",
    "* 请尝试读入t_alibaba_data31，列标就使用其数据第一行，注意brand id要设置为字符串\n",
    "\n",
    "* 请尝试读入t_alibaba_data31，列标用a,b,c,d替代\n",
    "\n",
    "* 请读入t_alibaba_data311，注意其时间列要读为时间戳\n",
    "\n",
    "* 请自行把“2019-10-15日程的签到详情(1)”转为csv格式，文件名随意，然后读入，注意编码设置\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### json数据的读取问题\n",
    "\n",
    "* pandas对json数据的读取本质上都是要把json数据转换为数据框"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZUAAABaCAIAAAD/8Fy5AAAVT0lEQVR4Ae1dX2gcR9KvvbtwB5cjkq1oDX5REq9Big2HT585JBTjtcFIhEMYI0wg5EWsBHqwXvKU4EXBb4aPFXyCXaGHmANjFiOEybdLPmIld0ZLEnzGYPkEJ/8RJA+WZVsKdw95uGO+6pnZmdmZnr89MzuzqkFoe6q7q6t+3VNTXd0zk5Ek6ccff3z8+DHQkVoEtra2+vr6Tp06RV3Zrj6kLmgL8r9oS6vUKCFACBAC4giQ/RLHkDgQAoRAexDIfPPNN+1pmVolBAgBQkAMgcwPP/wgxoFqEwKEACHQHgR+dfv27fa0TK0SAoQAISCGwK+w+nfffSfGhGoTAoQAIdAGBJj9wuOTTz5REsn/f/jw4efPn/f29nr5n3x1SEJCgBAIjED61h+9mC2lTGBQqCIhQAikAoH02S+PnheasFR0AAlJCBACgRFIn/0i/ytwZ1NFQqDDEEif/SL/q8OGIKlDCARGIA77dX95aWlp+f5eYCFbKqqxrUymN5sFh/+9vS3V8KQOc5nm35Q5Uzl/MS8XsORuTGXmMpm54XksdmdYTk/V+SxsqOIcbBhbyGVUchheWOhhEBy0MGY5NGUsFgxJB+Z61rLW0xnY0MlhpcS1EOfgSRcjDnceWavcGWYDvszGdSqPKO3Xnmy4lpaevD34TnjgKP4X8vvXP/9p94e5QeJfdViY5Qv65sAQyzh2FP/1HGPJ7ECO/Xg+xDm4NKWa3gy8W3IpKZDtoEV/RSrWCq68HTi41vVaAC041KAosb+JAlTDN2HiWohzcENDvl1rOBRrsJoDnglDPtuzdjlujbQ7P0r71fX785PsOP/7rhDVVP0vN45o5rhFsiV5YFe4mYzIClhye47KRkuupI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SjTOB4w242dyMiDfW6jr0c2Jwyq7GUHe2NgUcgoe5jM5ZiYhd8x38Co4DLl9UocWXQBxsNl9GhcNoJQ+zptVGecMqfzW2iR3nNzgOrGbrMGLb4krtsukc3WIhRRn/wvniBfz4I9qs5vGOaPALGXFNFdeoNVsV/cWtm3m2KV/lky1tzkx8tDCbm6uW4o5b4zSYXZSzsig26491OZ5bCDksxlbcFgGGStPSp2z/hApGYUJai9X52sEoZAPmUBTDwQ1GRoOD0iquR/ewZzYMMhRqRWnUcB5xEleiZ3ABxyBBKCtTEUsdOvs41h/DFZq7/mhn1FqalgO+jFLgbGFtKZnmE7wxo6HBXa6xmpXkIUY4YJ9om2246xwKRErXpXT9Mcr5YzRj2s5UWenm9uUtymZix53jLjEci/vceGGvEg7a0Mbx0KnrHFHOHzX8Qk1wp4pW46VQTC1jBKnoO1Zj4pHs00eAy66nOltHLz1AOMgo4fND+r5rC27s+aGwd/5aGomWkD77ZWeqrPRokUsm9yMwLSVTsnilIhzixbtdraVv/ujd/2oXptQuIUAIxINA+uyX1c+yo8SDILVCCBAC7UIgffaL/K92jRVqlxBIGgLps1923paVnjSsSR5CgBAIF4H02S/yv8IdAcSNEEgvAumzX1Y/y46S3l4hyQkBQsALAumzX+R/eelXKkMI7AcE0me/7LwtK30/9B/pSAjsZwTSZ7/I/9rP45V0JwSMCKTPfln9LDuKUU9KEwKEQOchkD77Rf5X541C0ogQCIZA+uyXnbdlpQdDhGoRAoRAWhBIn/0i/ystY4vkJASiRiB99svqZ9lRosaO+BMChEB7EUif/SL/q70jhlonBJKDQPrsl523ZaUnB2WShBAgBKJAIH32i/yvKMYB8SQE0ohA+uyX1c+yo6SxP0hmQoAQ8I5A+uwX+V/ee5dKEgKdjUD67Jedt2Wld3bPkXaEACGQPvtF/heNWkKAEFAQ+H8b9EeDwA7pdgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from IPython.display import Image\n",
    "Image(\"4.png\")\n",
    "#json数据的标准格式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   a  b  c\n",
      "0  1  2  3\n",
      "1  1  3  1\n",
      "2  6  2  3\n"
     ]
    }
   ],
   "source": [
    "d = pd.read_json(r'D:\\try\\js1.json')\n",
    "print(d)\n",
    "#注意pandas要求的json数据要符合上面的标准格式"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "shoes1.json中的一行数据（数据来源为2017年从淘宝爬取，例子只选取了其中五行）\n",
    "\n",
    "{\"_id\":{\"$oid\":\"5aa77042be9b0338dc1faab5\"},\"title\":\"意尔康旗舰店官方店男鞋春秋真皮爸爸鞋中老年人商务休闲皮鞋子男\",\"url\":\"http://detail.tmall.com/item.htm?id=545941839337\\u0026ns=1\\u0026abbucket=9\",\"price\":\"199.00\",\"location\":\"浙江 丽水\",\"sales\":\"1607人付款\",\"nick\":\"意尔康皮鞋旗舰店\",\"itemid\":\"545941839337\",\n",
    " \"info\":{\"上市年份季节\":\"2017年秋季\",\"货号\":\"7341ZL97655W\",\"销售渠道类型\":\"商场同款(线上线下都销售)\",\"鞋垫材质\":\"二层猪皮\",\"鞋跟高\":\"低跟(1-3cm)\",\"品牌\":\"YEARCON/意尔康\",\"鞋头款式\":\"圆头\",\"闭合方式\":\"套脚\",\"鞋底材质\":\"塑胶\",\"鞋面材质\":\"头层牛皮（除牛反绒）\",\"真皮材质工艺\":\"修面皮\",\"鞋面内里材质\":\"二层猪皮\",\"鞋制作工艺\":\"注压鞋\",\"跟底款式\":\"平跟\",\"图案\":\"纯色\",\"流行元素\":\"金属\",\"风格\":\"商务\",\"细分风格\":\"商务休闲\",\"场合\":\"办公室\",\"季节\":\"夏季\",\"颜色分类\":\"黑色棕色黑色加绒版棕色加绒版黑色镂空棕色镂空\",\"尺码\":\"38394041424344\",\"款式\":\"商务休闲鞋\",\"功能\":\"轻质\",\"适用对象\":\"青年（18-40周岁）中年（40-60周岁）老年（60周岁以上）\",\"低帮鞋品名\":\"商务休闲鞋\"}},"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>_id</th>\n",
       "      <th>info</th>\n",
       "      <th>itemid</th>\n",
       "      <th>location</th>\n",
       "      <th>nick</th>\n",
       "      <th>price</th>\n",
       "      <th>sales</th>\n",
       "      <th>title</th>\n",
       "      <th>url</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>{'$oid': '5aa77041be9b0338dc1faab4'}</td>\n",
       "      <td>{'上市年份季节': '2018年春季', '货号': '8142ZR90254W', '销...</td>\n",
       "      <td>562121114807</td>\n",
       "      <td>浙江 丽水</td>\n",
       "      <td>意尔康皮鞋旗舰店</td>\n",
       "      <td>269</td>\n",
       "      <td>1583人付款</td>\n",
       "      <td>意尔康男鞋2018春季新款英伦真皮商务休闲皮鞋青年男士皮鞋子男潮</td>\n",
       "      <td>http://detail.tmall.com/item.htm?id=5621211148...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>{'$oid': '5aa77042be9b0338dc1faab5'}</td>\n",
       "      <td>{'上市年份季节': '2017年秋季', '货号': '7341ZL97655W', '销...</td>\n",
       "      <td>545941839337</td>\n",
       "      <td>浙江 丽水</td>\n",
       "      <td>意尔康皮鞋旗舰店</td>\n",
       "      <td>199</td>\n",
       "      <td>1607人付款</td>\n",
       "      <td>意尔康旗舰店官方店男鞋春秋真皮爸爸鞋中老年人商务休闲皮鞋子男</td>\n",
       "      <td>http://detail.tmall.com/item.htm?id=5459418393...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>{'$oid': '5aa77042be9b0338dc1faab6'}</td>\n",
       "      <td>{'鞋垫材质': '二层猪皮', '鞋跟高': '平跟(小于等于1cm)', '品牌': '...</td>\n",
       "      <td>563340844728</td>\n",
       "      <td>浙江 温州</td>\n",
       "      <td>吸引力xl</td>\n",
       "      <td>148</td>\n",
       "      <td>248人付款</td>\n",
       "      <td>2017新款正品意尔康男鞋男士商务正装皮鞋透气真皮系带尖头办公室</td>\n",
       "      <td>http://item.taobao.com/item.htm?id=56334084472...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>{'$oid': '5aa77042be9b0338dc1faab7'}</td>\n",
       "      <td>{'货号': '883053', '鞋垫材质': '头层猪皮', '鞋跟高': '平跟(小于...</td>\n",
       "      <td>561684297836</td>\n",
       "      <td>浙江 温州</td>\n",
       "      <td>乙方乙方88888</td>\n",
       "      <td>158</td>\n",
       "      <td>195人付款</td>\n",
       "      <td>皮鞋男正品意尔康休闲商务真皮一脚蹬爸爸鞋春季新款圆头透气男鞋</td>\n",
       "      <td>http://item.taobao.com/item.htm?id=56168429783...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>{'$oid': '5aa77042be9b0338dc1faab8'}</td>\n",
       "      <td>{'上市年份季节': '2017年秋季', '货号': '7511ZE97187W', '销...</td>\n",
       "      <td>555004335522</td>\n",
       "      <td>浙江 丽水</td>\n",
       "      <td>意尔康男鞋旗舰店</td>\n",
       "      <td>279</td>\n",
       "      <td>37人付款</td>\n",
       "      <td>意尔康男鞋2018春季真皮套脚休闲鞋潮流新款舒适一脚蹬单鞋皮鞋</td>\n",
       "      <td>http://detail.tmall.com/item.htm?id=5550043355...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    _id  \\\n",
       "0  {'$oid': '5aa77041be9b0338dc1faab4'}   \n",
       "1  {'$oid': '5aa77042be9b0338dc1faab5'}   \n",
       "2  {'$oid': '5aa77042be9b0338dc1faab6'}   \n",
       "3  {'$oid': '5aa77042be9b0338dc1faab7'}   \n",
       "4  {'$oid': '5aa77042be9b0338dc1faab8'}   \n",
       "\n",
       "                                                info        itemid location  \\\n",
       "0  {'上市年份季节': '2018年春季', '货号': '8142ZR90254W', '销...  562121114807    浙江 丽水   \n",
       "1  {'上市年份季节': '2017年秋季', '货号': '7341ZL97655W', '销...  545941839337    浙江 丽水   \n",
       "2  {'鞋垫材质': '二层猪皮', '鞋跟高': '平跟(小于等于1cm)', '品牌': '...  563340844728    浙江 温州   \n",
       "3  {'货号': '883053', '鞋垫材质': '头层猪皮', '鞋跟高': '平跟(小于...  561684297836    浙江 温州   \n",
       "4  {'上市年份季节': '2017年秋季', '货号': '7511ZE97187W', '销...  555004335522    浙江 丽水   \n",
       "\n",
       "        nick  price    sales                             title  \\\n",
       "0   意尔康皮鞋旗舰店    269  1583人付款  意尔康男鞋2018春季新款英伦真皮商务休闲皮鞋青年男士皮鞋子男潮   \n",
       "1   意尔康皮鞋旗舰店    199  1607人付款    意尔康旗舰店官方店男鞋春秋真皮爸爸鞋中老年人商务休闲皮鞋子男   \n",
       "2      吸引力xl    148   248人付款  2017新款正品意尔康男鞋男士商务正装皮鞋透气真皮系带尖头办公室   \n",
       "3  乙方乙方88888    158   195人付款    皮鞋男正品意尔康休闲商务真皮一脚蹬爸爸鞋春季新款圆头透气男鞋   \n",
       "4   意尔康男鞋旗舰店    279    37人付款   意尔康男鞋2018春季真皮套脚休闲鞋潮流新款舒适一脚蹬单鞋皮鞋   \n",
       "\n",
       "                                                 url  \n",
       "0  http://detail.tmall.com/item.htm?id=5621211148...  \n",
       "1  http://detail.tmall.com/item.htm?id=5459418393...  \n",
       "2  http://item.taobao.com/item.htm?id=56334084472...  \n",
       "3  http://item.taobao.com/item.htm?id=56168429783...  \n",
       "4  http://detail.tmall.com/item.htm?id=5550043355...  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d1 = pd.read_json(r'D:\\try\\shoes1.json')\n",
    "d1\n",
    "#注意info中的双层结构并没有被解析,read_json通常只能解析一层"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "#d1.info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    " from pandas.io.json import json_normalize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>上市年份季节</th>\n",
       "      <th>低帮鞋品名</th>\n",
       "      <th>功能</th>\n",
       "      <th>品牌</th>\n",
       "      <th>图案</th>\n",
       "      <th>场合</th>\n",
       "      <th>季节</th>\n",
       "      <th>尺码</th>\n",
       "      <th>款式</th>\n",
       "      <th>流行元素</th>\n",
       "      <th>...</th>\n",
       "      <th>闭合方式</th>\n",
       "      <th>鞋制作工艺</th>\n",
       "      <th>鞋垫材质</th>\n",
       "      <th>鞋头款式</th>\n",
       "      <th>鞋底材质</th>\n",
       "      <th>鞋跟高</th>\n",
       "      <th>鞋面内里材质</th>\n",
       "      <th>鞋面材质</th>\n",
       "      <th>颜色分类</th>\n",
       "      <th>风格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018年春季</td>\n",
       "      <td>商务休闲鞋</td>\n",
       "      <td>轻质</td>\n",
       "      <td>YEARCON/意尔康</td>\n",
       "      <td>纯色</td>\n",
       "      <td>日常</td>\n",
       "      <td>春秋</td>\n",
       "      <td>383940414243</td>\n",
       "      <td>商务休闲鞋</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>松紧带</td>\n",
       "      <td>注压鞋</td>\n",
       "      <td>PU</td>\n",
       "      <td>圆头</td>\n",
       "      <td>塑胶</td>\n",
       "      <td>NaN</td>\n",
       "      <td>PU</td>\n",
       "      <td>头层牛皮（除牛反绒）</td>\n",
       "      <td>黑色土黄</td>\n",
       "      <td>商务</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017年秋季</td>\n",
       "      <td>商务休闲鞋</td>\n",
       "      <td>轻质</td>\n",
       "      <td>YEARCON/意尔康</td>\n",
       "      <td>纯色</td>\n",
       "      <td>办公室</td>\n",
       "      <td>夏季</td>\n",
       "      <td>38394041424344</td>\n",
       "      <td>商务休闲鞋</td>\n",
       "      <td>金属</td>\n",
       "      <td>...</td>\n",
       "      <td>套脚</td>\n",
       "      <td>注压鞋</td>\n",
       "      <td>二层猪皮</td>\n",
       "      <td>圆头</td>\n",
       "      <td>塑胶</td>\n",
       "      <td>低跟(1-3cm)</td>\n",
       "      <td>二层猪皮</td>\n",
       "      <td>头层牛皮（除牛反绒）</td>\n",
       "      <td>黑色棕色黑色加绒版棕色加绒版黑色镂空棕色镂空</td>\n",
       "      <td>商务</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>透气</td>\n",
       "      <td>YEARCON/意尔康</td>\n",
       "      <td>纯色</td>\n",
       "      <td>办公室</td>\n",
       "      <td>春秋</td>\n",
       "      <td>38 39 40 41 42 43 44</td>\n",
       "      <td>德比鞋（正装皮鞋）</td>\n",
       "      <td>车缝线</td>\n",
       "      <td>...</td>\n",
       "      <td>系带</td>\n",
       "      <td>胶粘鞋</td>\n",
       "      <td>二层猪皮</td>\n",
       "      <td>尖头</td>\n",
       "      <td>橡胶</td>\n",
       "      <td>平跟(小于等于1cm)</td>\n",
       "      <td>二层猪皮</td>\n",
       "      <td>头层牛皮（除牛反绒）</td>\n",
       "      <td>黑色</td>\n",
       "      <td>商务</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>透气</td>\n",
       "      <td>YEARCON/意尔康</td>\n",
       "      <td>纯色</td>\n",
       "      <td>日常</td>\n",
       "      <td>冬季</td>\n",
       "      <td>37 38 39 40 41 42 43 44</td>\n",
       "      <td>商务休闲鞋</td>\n",
       "      <td>素面</td>\n",
       "      <td>...</td>\n",
       "      <td>套脚</td>\n",
       "      <td>注压鞋</td>\n",
       "      <td>头层猪皮</td>\n",
       "      <td>圆头</td>\n",
       "      <td>橡胶</td>\n",
       "      <td>平跟(小于等于1cm)</td>\n",
       "      <td>头层猪皮</td>\n",
       "      <td>头层牛皮（除牛反绒）</td>\n",
       "      <td>黑色真皮 棕色真皮 黑色加绒真皮 棕色加绒真皮</td>\n",
       "      <td>商务</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017年秋季</td>\n",
       "      <td>休闲皮鞋</td>\n",
       "      <td>耐磨</td>\n",
       "      <td>YEARCON/意尔康</td>\n",
       "      <td>纯色</td>\n",
       "      <td>日常</td>\n",
       "      <td>春秋</td>\n",
       "      <td>383940414243</td>\n",
       "      <td>休闲皮鞋</td>\n",
       "      <td>车缝线</td>\n",
       "      <td>...</td>\n",
       "      <td>套脚</td>\n",
       "      <td>胶粘鞋</td>\n",
       "      <td>二层猪皮</td>\n",
       "      <td>圆头</td>\n",
       "      <td>橡胶</td>\n",
       "      <td>平跟(小于等于1cm)</td>\n",
       "      <td>布</td>\n",
       "      <td>头层牛皮（除牛反绒）</td>\n",
       "      <td>黑色单鞋土黄单鞋</td>\n",
       "      <td>休闲</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    上市年份季节  低帮鞋品名  功能           品牌  图案   场合  季节                       尺码  \\\n",
       "0  2018年春季  商务休闲鞋  轻质  YEARCON/意尔康  纯色   日常  春秋             383940414243   \n",
       "1  2017年秋季  商务休闲鞋  轻质  YEARCON/意尔康  纯色  办公室  夏季           38394041424344   \n",
       "2      NaN    NaN  透气  YEARCON/意尔康  纯色  办公室  春秋     38 39 40 41 42 43 44   \n",
       "3      NaN    NaN  透气  YEARCON/意尔康  纯色   日常  冬季  37 38 39 40 41 42 43 44   \n",
       "4  2017年秋季   休闲皮鞋  耐磨  YEARCON/意尔康  纯色   日常  春秋             383940414243   \n",
       "\n",
       "          款式 流行元素 ... 闭合方式 鞋制作工艺  鞋垫材质 鞋头款式 鞋底材质          鞋跟高 鞋面内里材质  \\\n",
       "0      商务休闲鞋  NaN ...  松紧带   注压鞋    PU   圆头   塑胶          NaN     PU   \n",
       "1      商务休闲鞋   金属 ...   套脚   注压鞋  二层猪皮   圆头   塑胶    低跟(1-3cm)   二层猪皮   \n",
       "2  德比鞋（正装皮鞋）  车缝线 ...   系带   胶粘鞋  二层猪皮   尖头   橡胶  平跟(小于等于1cm)   二层猪皮   \n",
       "3      商务休闲鞋   素面 ...   套脚   注压鞋  头层猪皮   圆头   橡胶  平跟(小于等于1cm)   头层猪皮   \n",
       "4       休闲皮鞋  车缝线 ...   套脚   胶粘鞋  二层猪皮   圆头   橡胶  平跟(小于等于1cm)      布   \n",
       "\n",
       "         鞋面材质                     颜色分类  风格  \n",
       "0  头层牛皮（除牛反绒）                     黑色土黄  商务  \n",
       "1  头层牛皮（除牛反绒）   黑色棕色黑色加绒版棕色加绒版黑色镂空棕色镂空  商务  \n",
       "2  头层牛皮（除牛反绒）                       黑色  商务  \n",
       "3  头层牛皮（除牛反绒）  黑色真皮 棕色真皮 黑色加绒真皮 棕色加绒真皮  商务  \n",
       "4  头层牛皮（除牛反绒）                 黑色单鞋土黄单鞋  休闲  \n",
       "\n",
       "[5 rows x 26 columns]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c1=json_normalize(d1[\"info\"])\n",
    "c1\n",
    "#多层结构可以使用json_normalize进行进一步的解析，对于无法对应的列默认置空"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 课间题\n",
    "\n",
    "* 请自行读入js1与shoes1两份数据\n",
    "\n",
    "* 请解析下shoes1的info列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
